package b_Stack;

import a_ArrayList.ArrayList;

public class ArrayStack<E> implements Stack<E>{
	
	private ArrayList<E> array;

    public ArrayStack(int Capacity) {
		array = new ArrayList<>(Capacity);	
	}
    
    public ArrayStack() {
    	array= new ArrayList<>();
    }
    
	@Override
	public void push(E e) {
		array.addLast(e);
	}

	@Override
	public E pop() {
		return array.removeLast();
	}

	@Override
	public E peek() {
		return array.get(array.getSize()-1);
	}

	@Override 
	public int getSize() {
		return array.getSize();
	}
	
    public int getCapacity() {
    	return array.getCapacity();
    }

	@Override
	public boolean isEmpty() {
		return array.isEmpty();
	}
	
	@Override
	public String toString() {
		StringBuilder result=new StringBuilder();
		result.append("Stack:[");
	    for(int i=0;i<array.getSize();i++) {
	    	if(i!=0)
	    		result.append(", ");
	    	result.append(array.get(i));
	    }
	    result.append("] top");
		return result.toString();
	}
	
}
